class TalkDialog extends renderer.DisplayObjectContainer {

    private titleText: renderer.TextField;
    private npcName: renderer.TextField;
    private contentText: renderer.TextField;
    private mission: Mission;
    private npc: Npc;
    private portrait: renderer.Bitmap;


    constructor(npc1: Npc) {
        super();
        this.npc = npc1;

        const background = new renderer.Bitmap(0, 0, dialogBackgroundTexture);
        this.addChild(background);


        // //加载头像
        const portrait = new renderer.Bitmap(0, 0, npc1.portraitTexture);

        portrait.image = this.npc.portraitTexture;






        portrait.x = 100;
        portrait.y = 200;

        this.addChild(portrait);




        const textField = new renderer.TextField();
        this.addChild(textField);
        textField.text = "对话框";
        textField.style = "32px Ariel";
        textField.x = 250;
        textField.y = 80;

        this.titleText = new renderer.TextField();
        this.addChild(this.titleText);
        this.titleText.x = 250;
        this.titleText.y = 110;


        this.npcName = new renderer.TextField();
        //  this.npcName.text = this.npc.name + " :";
        this.npcName.text = this.npc.name
        this.npcName.x = 130;
        this.npcName.y = 300;
        this.addChild(this.npcName);

        this.contentText = new renderer.TextField();
        this.addChild(this.contentText);
        this.contentText.x = 250;
        this.contentText.y = 300;
        this.addEventListener("click", () => {
            this.dispatchEvent('close', {});
        });

    }

    update() {
        const mission = this.mission;
        let content = ""

        this.titleText.text = "任务： " + mission.title;


        if (mission.status == MissionStatus.CAN_ACCEPT) {
            content = mission.canAcceptContent

        }
        else if (mission.status == MissionStatus.CAN_SUBMIT) {
            content = mission.canSubmitContent

        }

        this.contentText.text = content;

        // string = string.replace(/\n/g,"<br>");
        // this.contentText.text = this.contentText.text.replace(/\r\n/g, " \n ");
    }

    setMission(mission: Mission) {
        this.mission = mission;
        this.update();
    }

    setNpc(npc: Npc) {
        this.npc = npc;
        this.update();
    }


}